package com.java83;

import com.java83.entity.RbacManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.redis.core.RedisTemplate;

import java.util.Set;
import java.util.concurrent.TimeUnit;

@SpringBootTest
public class Test {
    @Autowired
    RedisTemplate redisTemplate;
    @org.junit.Test
    public void testString(){
        redisTemplate.opsForValue().set("myspringbootkey","test1");
        System.out.println(redisTemplate.opsForValue().get("myspringbootkey"));
    }
    @org.junit.Test
    public void testHash(){
        redisTemplate.opsForHash().put("myspringboothash","myfield","myhashvalue");
        Object o = redisTemplate.opsForHash().get("myspringboothash", "myfield");
        System.out.println(o);
        //配置过期时间
        redisTemplate.expire("myspringboothash",100, TimeUnit.SECONDS);
    }
    @org.junit.Test
    public void testObject(){
        RbacManager rbacManager = new RbacManager();
        rbacManager.setAccount("amdin");
        Set myobject = redisTemplate.keys("myobject");
        Boolean myobject1 = redisTemplate.hasKey("myobject");
        redisTemplate.opsForValue().set("myobject",rbacManager);
        System.out.println(redisTemplate.opsForValue().get("myobject"));
    }
}